﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.Drawing;

namespace Prodcrast
{
    class EpisodeGridViewColumn
        : DataGridViewColumn
    {
        public EpisodeGridViewColumn() 
            : base(new EpisodeGridViewCell())
        { 
            
        }
    }

    class EpisodeGridViewCell 
        : DataGridViewTextBoxCell
    {
        public EpisodeGridViewCell()
        {

        }

        public override bool ReadOnly
        {
            get { return true; }
        }

        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            Episode ep = value as Episode;
            
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, null, "", errorText, cellStyle, advancedBorderStyle, paintParts);

            if (ep != null)
            {
                if (ep.DownloadActive)
                {
                    Rectangle bounds = cellBounds;
                    bounds.Inflate(-2, -2);

                    ProgressBarRenderer.DrawHorizontalBar(graphics, bounds);

                    bounds.Inflate(-2, -2);
                    bounds.Width = (int)(bounds.Width * ep.ProgressPercent);
                    graphics.FillRectangle(new SolidBrush(Color.Green), bounds);
                }
            }
        }
    }
}
